package com.gxr.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import util.StrConvert;

import com.dao.ObjectDao;
import com.pro.bean.Unit;
import com.pro.bean.Users;

public class EditUserServlet extends HttpServlet {

	/**
	 * �����û���� ��ת���༭����
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("UTF-8");
		String userid=(String)request.getParameter("userId");
		
		String username = StrConvert.ToCN(request.getParameter("username"));

		//String username=(String)request.getParameter("username");
		System.out.println("EditUserServlet"+username);
		String useremail=(String)request.getParameter("useremail");
		String userunit=(String)request.getParameter("userunit");
		String password=(String)request.getParameter("userpassword");
		/*byte tempbyte[]=username.getBytes("ISO-8859-1");
		username=new String(tempbyte,"gb2312");*/
		
		HttpSession session=request.getSession();
		session.setAttribute("userid", userid);
		session.setAttribute("username",username);
		session.setAttribute("email", useremail);
		session.setAttribute("company", userunit);
		session.setAttribute("password", password);
		//System.out.println(useremail);
		
		Unit unit =new Unit();
		ObjectDao ObjectDao=new ObjectDao();
		List lUnit=ObjectDao.findall(unit);
		HttpSession sessionUnit=request.getSession();
		sessionUnit.setAttribute("list", lUnit);
		
		RequestDispatcher dispatcher=request.getRequestDispatcher("../gxr/admin_userinfo_e.jsp");
		dispatcher.forward(request, response);
		
		
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		/*response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("UTF-8");
		
		String userid=request.getParameter("userid");
		System.out.println("EditUserServlet"+userid);
		
		String username=request.getParameter("username");
		System.out.println("EditUserServlet"+username);
		String password=request.getParameter("password");
		String email=request.getParameter("email");
		String company=request.getParameter("company");

		
		HttpSession session=request.getSession();
		session.setAttribute("userid", userid);
		session.setAttribute("username", username);
		session.setAttribute("password", password);
		session.setAttribute("email", email);
		session.setAttribute("company", company);*/
		Unit unit =new Unit();
		ObjectDao ObjectDao=new ObjectDao();
		List lUnit=ObjectDao.findall(unit);
		HttpSession sessionUnit=request.getSession();
		sessionUnit.setAttribute("list", lUnit);

		RequestDispatcher dispatcher=request.getRequestDispatcher("../gxr/admin_userinfo_e.jsp");
		dispatcher.forward(request, response);
		
	}

}
